package com.study.lihan.threalLocal;

import com.study.lihan.bean.Person;

import java.util.concurrent.TimeUnit;

/**
 * @Author: lihan
 * @Date : 2022/1/2- 01
 * @DESCRIPTION: com.study.lihan.threalLocal
 * @version: 1.0
 */
public class TestThreadLocal {
//    volatile static  Person p = new Person();
    static ThreadLocal<Person> tl = new ThreadLocal<>();
    public static void main(String[] args) {
        new Thread(()->{
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(tl.get());
        }).start();

        new Thread(()->{
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            tl.set(new Person());
        }).start();

    }
}
